package com.hk.controller.admin;

import com.hk.model.dto.BusinessPageQueryDTO;
import com.hk.model.dto.RequestData;
import com.hk.model.vo.BusinessPageQueryVO;
import com.hk.result.PageResult;
import com.hk.result.Result;
import com.hk.service.BusinessService;
import com.hk.service.CustomerService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.Data;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.io.Serializable;
import java.util.List;

@RestController
@RequestMapping("/business")
@Slf4j
@RequiredArgsConstructor
@Api(tags = "商机管理")
public class BusinessController {
    private final BusinessService businessService;

    @ApiOperation("分页查询商机")
    @GetMapping("/list")
    public PageResult list(BusinessPageQueryDTO businessPageQueryDTO) {
        return businessService.getPage(businessPageQueryDTO);
    }

    /**
     * 新增商机
     */
    @ApiOperation("新增商机")
    @PostMapping
    public Result save(@RequestBody BusinessPageQueryVO businessPageQueryVO) {
        log.info("新增商机:{}", businessPageQueryVO);
        businessService.saveBusiness(businessPageQueryVO);
        return Result.success();
    }

    /**
     * 分配商机
     */
    @PutMapping("/assignment")//todo : 与人员表进行联查判断，判断被指派人有多少商机正在跟进
    @ApiOperation("分配商机")
    public Result assignment(RequestData requestData) {
        log.info("分配商机:{}", requestData);
        businessService.assignBusiness(requestData);
        return Result.success();
    }

    @GetMapping("/{id}")
    @ApiOperation("根据id回显客户基本信息")
    public Result getByCustomerInfoId(@PathVariable Long id){
        return Result.success(businessService.getByCustomerInfoId(id));
    }
}


